home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / AppWannabe / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  5.6 KB  |  204 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file is where you place various definitions and constant values for
  20. ** DTS.Lib..framework's use.  You will also add some code within the two
  21. ** functions to handle the various document types. */
  22.  
  23.  
  24.  
  25. /*****************************************************************************/
  26.  
  27.  
  28.  
  29. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  30. #include "App.defs.h"        /* Get various application definitions.            */
  31. #include "App.protos.h"        /* Get the prototypes for application.            */
  32.  
  33. #ifndef __ERRORS__
  34. #include <Errors.h>
  35. #endif
  36.  
  37. #ifndef __UTILITIES__
  38. #include "Utilities.h"
  39. #endif
  40.  
  41.  
  42.  
  43. /* In this file, we first set some global values.  This allows the application and
  44. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  45.  
  46.  
  47. short        gTypeListLen = 1;
  48. SFTypeList    gTypeList = {kDocFileType};
  49.     /* Here we declare the various document types that Wannabe can support.
  50.     ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
  51.  
  52.  
  53.  
  54. /* Some DTS.Lib..framework gTypeList usage notes:
  55. **
  56. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  57. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  58. **     The index at which the match is found (+1) is used as the string number in the
  59. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  60. **     resource, then the last string is used.
  61. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  62. **     can be selected. */
  63.  
  64.  
  65.  
  66. #if defined(powerc) || defined (__powerc)
  67. #pragma options align=mac68k
  68. #endif
  69. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document  */
  70.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as   */
  71.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler   */
  72.     TheDoc            doc;            /* will place on the end of each.                            */
  73. } DocFileTypeRec;                    /* The only place that this should be used is in this file. */
  74. #if defined(powerc) || defined(__powerc)
  75. #pragma options align=reset
  76. #endif
  77. #if defined(powerc) || defined(__powerc)
  78. #pragma options align=reset
  79. #endif
  80.  
  81.  
  82.  
  83. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  84. ** application.  The first 16 are reserved for the framework.  Our application-specific
  85. ** objects start at 16. */
  86.  
  87. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  88. /* 1  */                                         TRootObj,
  89. /* 2  */                                         TUndoObj,
  90. /* 3  */                                         TUndoTaskObj,
  91. /* 4  */                                         TUndoPartObj,
  92. /* 5  */                                         nil,
  93. /* 6  */                                         nil,
  94. /* 7  */                                         nil,
  95. /* 8  */                                         nil,
  96. /* 9  */                                         nil,
  97. /* 10 */                                         nil,
  98. /* 11 */                                         nil,
  99. /* 12 */                                         nil,
  100. /* 13 */                                         nil,
  101. /* 14 */                                         nil,
  102. /* 15 */                                         nil};
  103. /* 16 Start of app-specific procs. */
  104.  
  105.  
  106.  
  107. /* The framework needs to know the minimum object sizes.  This table is used by the
  108. ** framework to make sure that the object is created at least minimally. */
  109.  
  110. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  111. /* 1  */                                         sizeof(RootObj),
  112. /* 2  */                                         sizeof(UndoObj),
  113. /* 3  */                                         sizeof(UndoTaskObj),
  114. /* 4  */                                         sizeof(UndoPartObj),
  115. /* 5  */                                         0,
  116. /* 6  */                                         0,
  117. /* 7  */                                         0,
  118. /* 8  */                                         0,
  119. /* 9  */                                         0,
  120. /* 10 */                                         0,
  121. /* 11 */                                         0,
  122. /* 12 */                                         0,
  123. /* 13 */                                         0,
  124. /* 14 */                                         0,
  125. /* 15 */                                         0};
  126. /* 16 Start of app-specific sizes. */
  127.  
  128.  
  129.  
  130. /*****************************************************************************/
  131. /*****************************************************************************/
  132.  
  133.  
  134.  
  135. /* •• Called by DTS.Lib..framework. •• */
  136.  
  137. /* Do any additional document initialization here.  All fields not specifically set
  138. ** are already initialized to 0. */
  139.  
  140. #pragma segment File
  141. OSErr    InitDocument(FileRecHndl frHndl)
  142. {
  143.     OSErr    err;
  144.  
  145.     err = noErr;
  146.  
  147.     switch ((*frHndl)->fileState.sfType) {
  148.         case kDocFileType:
  149.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  150.             if (!err) {
  151.                 /* Any additional document initialization could go here. */
  152.             }
  153.             break;
  154.         case '6hlp':
  155.             err = HelpInitDocument(frHndl);
  156.             break;
  157. #if VH_VERSION
  158.         case kViewHierFileType:
  159.             return(VHInitDocument(frHndl));
  160.             break;
  161. #endif
  162.         default:
  163.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  164.             if (!err) {
  165.                 (*frHndl)->fileState.readDocumentProc  = nil;
  166.                 (*frHndl)->fileState.writeDocumentProc = nil;
  167.             }
  168.             break;
  169.     }
  170.  
  171.     return(err);
  172. }
  173.  
  174.  
  175.  
  176. /*****************************************************************************/
  177.  
  178.  
  179.  
  180. /* •• Called by DTS.Lib..framework. •• */
  181.  
  182. /* Return the initial size of the primary document handle, based on the OSType. */
  183.  
  184. #pragma segment File
  185. long    InitDocumentSize(OSType sftype)
  186. {
  187.     switch (sftype) {
  188.         case kDocFileType:
  189.             return(sizeof(DocFileTypeRec));
  190.             break;
  191. #if VH_VERSION
  192.         case kViewHierFileType:
  193.             return(VHFileTypeSize());
  194.             break;
  195. #endif
  196.         default:
  197.             return(sizeof(DocFileTypeRec));
  198.             break;
  199.     }
  200. }
  201.  
  202.  
  203.  
  204.